package com.dingding.service.core.common.dao.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.Phonevalidate;
import com.dingding.service.core.common.dao.IValidateDao;
import com.dingding.service.core.common.sql.ValidateSQL;

/**
 * 
 * @ClassName: ValidateDaoImpl 
 * @Description: 验证 DAO实现类 
 * @author YHQ
 * @date 2016年12月5日 上午11:08:15
 * @since V2.5.7
 * 
 */
@Component("validateDao")
public class ValidateDaoImpl implements IValidateDao{

	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * 
	 * @Title: getPhoneValidate 
	 * @Description: 根据手机号获取手机验证码信息
	 * @param telPhone 手机号
	 * @author YHQ 
	 * @since V2.5.7
	 * @return Phonevalidate  手机验证码信息对象
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public Phonevalidate getPhoneValidate(String telPhone) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(Phonevalidate.class, ValidateSQL.GET_PHONE_VALIDATE_BY_ID, telPhone);
		} catch (Exception e) {
			log.error("根据手机号获取手机验证码信息时出现异常   类：" + this.getClass() + " getPhoneValidate()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: updateValidate 
	 * @Description: 修改手机验证码信息
	 * @param phonevalidate 要修改的验证码对象
	 * @author YHQ 
	 * @since V2.5.7
	 * @return void    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public void updateValidate(Phonevalidate phonevalidate) {
		
		try {
			baseDaoX.update(phonevalidate);
		} catch (Exception e) {
			log.error("修改手机验证码信息时出现异常   类：" + this.getClass() + " updateValidate", e);
		}
		
	}

}
